﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BSE.Windows.Test
{
    public partial class RegisterZYForm : BaseForm
    {
        private List<Sex> sexOptions = new List<Sex>();
        private List<Yaopin> yaopins = new List<Yaopin>();
        private List<Yishi> doctors = new List<Yishi>();
        private List<Chufang> chufangList = new List<Chufang>();
        private List<Keshi> keshiList = new List<Keshi>();
        private List<Person> takers = new List<Person>();
        private List<Person> senders = new List<Person>();
        private List<Person> auditors = new List<Person>();
        private Color normalColor;

        private bool isZhuyuan = true;

        private DateTimePicker startPicker = null;
        private DateTimePicker endPicker = null;
        private bool initCompleted = false;

        public bool IsZhuyuan
        {
            get { return isZhuyuan; }
            set 
            { 
                isZhuyuan = value;
                if (isZhuyuan)
                {
                    this.Text = "住院处方";
                    if (dataGridView1.Columns.Count >= 8)
                        dataGridView1.Columns[7].HeaderText = "住院号";
                }
                else
                {
                    this.Text = "门诊处方";
                    if (dataGridView1.Columns.Count >= 8)
                        dataGridView1.Columns[7].HeaderText = "门诊号";
                }
            }
        }

        public RegisterZYForm()
        {
            sexOptions.Add(new Sex(0, "女"));
            sexOptions.Add(new Sex(1, "男"));

            InitializeComponent();
            InitToolStrip();
        }

        private void RegisterZYForm_Load(object sender, EventArgs e)
        {
            RefreshForm();
            initCompleted = true;
            normalColor = dataGridView1.DefaultCellStyle.BackColor;
        }

        public override void RefreshForm()
        {
            CreateGridView();
            LoadChufangList();
        }

        private void InitToolStrip()
        {
            startPicker = new DateTimePicker();
            startPicker.Width = 110;
            startPicker.Format = DateTimePickerFormat.Custom;
            startPicker.Value = DateTime.Now.AddDays(-1);
            startPicker.ValueChanged += new EventHandler(toolStripComboBoxDrug_SelectedIndexChanged);
            ToolStripControlHost host1 = new ToolStripControlHost(startPicker);
            toolStrip1.Items.Insert(1, host1);

            endPicker = new DateTimePicker();
            endPicker.Width = 110;
            endPicker.Format = DateTimePickerFormat.Custom;
            endPicker.ValueChanged += new EventHandler(toolStripComboBoxDrug_SelectedIndexChanged);
            host1 = new ToolStripControlHost(endPicker);
            toolStrip1.Items.Insert(3, host1);
        }

        private void LoadChufangList()
        {
            if (isZhuyuan)
                chufangList = AnesthesiaBLL.GetAllZhuyuanChufangList(
                    "",
                    startPicker.Value, endPicker.Value,
                    false, false, false);
            else
                chufangList = AnesthesiaBLL.GetAllMenzhenChufangList(
                    "",
                    DateTime.Now.AddDays(-30), DateTime.Now,
                    false, false, false);

            bindingSource1.DataSource = chufangList;
            dataGridView1.DataSource = bindingSource1;
        }

        private void CreateGridView()
        {
            yaopins = AnesthesiaBLL.GetAllYaopin();
            doctors = AnesthesiaBLL.GetYishiByKeshi(null);
            keshiList = AnesthesiaBLL.GetAllKeshi();
            takers = AnesthesiaBLL.GetPersons(Person.PERSON_TAKER);
            senders = AnesthesiaBLL.GetPersons(Person.PERSON_SENDER);
            auditors = AnesthesiaBLL.GetPersons(Person.PERSON_AUDITOR);

            // Initialize the DataGridView.
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.AutoSize = true;
            dataGridView1.Columns.Clear();
           
            //dataGridView1.Columns.Add(CreateComboBoxWithEnums());

            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "Serial";
            column.Name = "序号";
            column.Width = 60;
            dataGridView1.Columns.Add(column);

            CalendarColumn col = new CalendarColumn();
            col.DataPropertyName = "ChufangDate";
            col.Name = "日期";
            this.dataGridView1.Columns.Add(col);
            /*
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "ChufangDate";
            column.Name = "日期";
            dataGridView1.Columns.Add(column);
            */

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "PatientName";
            column.Name = "患者姓名";
            column.Width = 100;
            dataGridView1.Columns.Add(column);

            DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
            combo.DataSource = sexOptions;
            combo.ValueMember = "SexIndex";
            combo.DisplayMember = "SexLabel";
            combo.DataPropertyName = "PatientSex";
            combo.Name = "性别";
            combo.Width = 60;
            dataGridView1.Columns.Add(combo);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "PatientAge";
            column.Name = "年龄";
            column.Width = 60;
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "PatientCardNo";
            column.Name = "身份证号";
            column.Width = 150;
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "HospitalNo";
            column.Name = isZhuyuan?"住院号":"门诊号";
            column.Width = 80;
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "Illness";
            column.Name = "疾病名称";
            column.Width = 150;
            dataGridView1.Columns.Add(column);

            DataGridViewComboAssociatedBoxColumn cbo = new DataGridViewComboAssociatedBoxColumn();
            cbo.DataSource = yaopins;
            cbo.ValueMember = "YaopinCode";
            cbo.DisplayMember = "YaopinName";
            cbo.DataPropertyName = "YaopinCode";
            cbo.Name = "药品名称";
            cbo.Width = 130;
            dataGridView1.Columns.Add(cbo);

            /*
            combo = new DataGridViewComboBoxColumn();
            combo.DataSource = yaopins;
            combo.ValueMember = "YaopinCode";
            combo.DisplayMember = "YaopinName";
            combo.DataPropertyName = "YaopinCode";
            combo.Name = "药品名称";
            dataGridView1.Columns.Add(combo);
            */
            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "YaopinGuige";
            column.Name = "规格";
            column.ReadOnly = true;
            column.Width = 80;
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "YaopinDanwei";
            column.Name = "单位";
            column.Width = 60;
            column.ReadOnly = true;
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "ChufangYaopinCount";
            column.Name = "数量";
            column.Width = 60;
            dataGridView1.Columns.Add(column);

            cbo = new DataGridViewComboAssociatedBoxColumn();
            cbo.DataSource = doctors;
            cbo.ValueMember = "YishiCode";
            cbo.DisplayMember = "YishiName";
            cbo.DataPropertyName = "DoctorCode";
            cbo.Name = "处方医师";
            cbo.Width = 80;
            dataGridView1.Columns.Add(cbo);
            /*
            combo = new DataGridViewComboBoxColumn();
            combo.DataSource = doctors;
            combo.ValueMember = "YishiCode";
            combo.DisplayMember = "YishiName";
            combo.DataPropertyName = "DoctorCode";
            combo.Name = "处方医师";
            dataGridView1.Columns.Add(combo);
            */

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "ChufangCode";
            column.Name = "处方编号";
            column.Width = 80;
            dataGridView1.Columns.Add(column);

            /*
            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "TakerName";
            column.Name = "取药人姓名";
            dataGridView1.Columns.Add(column);
            */
            DataGridViewComboEditBoxColumn ceo = new DataGridViewComboEditBoxColumn();
            //ceo.DataSource = takers;
            ceo.ValueMember = "PersonName";
            ceo.DisplayMember = "PersonName";
            ceo.DataPropertyName = "TakerName";
            
            foreach (Person p in takers)
            {
                if ((p.IsZhuyuan == 1 && this.IsZhuyuan) || (p.IsZhuyuan == 0 && !this.IsZhuyuan))
                    ceo.Items.Add(p);
            }

            ceo.Name = "取药人";
            ceo.Width = 80;
            dataGridView1.Columns.Add(ceo);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "TakerCardNo";
            column.Name = "身份证号";
            dataGridView1.Columns.Add(column);
            /*
            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "ReleaserName";
            column.Name = "发药人";
            dataGridView1.Columns.Add(column);
            */
            ceo = new DataGridViewComboEditBoxColumn();
            ceo.ValueMember = "PersonName";
            ceo.DisplayMember = "PersonName";
            ceo.DataPropertyName = "ReleaserName";

            foreach (Person p in senders)
            {
                ceo.Items.Add(p);
            }

            ceo.Name = "发药人";
            ceo.Width = 80;
            dataGridView1.Columns.Add(ceo);

            /*
            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "AuditorName";
            column.Name = "复核人";
            dataGridView1.Columns.Add(column);
            */
            ceo = new DataGridViewComboEditBoxColumn();
            ceo.ValueMember = "PersonName";
            ceo.DisplayMember = "PersonName";
            ceo.DataPropertyName = "AuditorName";

            foreach (Person p in auditors)
            {
                ceo.Items.Add(p);
            }

            ceo.Name = "复核人";
            ceo.Width = 80;
            dataGridView1.Columns.Add(ceo);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "BatchNo";
            column.Name = "批号";
            column.Width = 100;
            dataGridView1.Columns.Add(column);

            combo = new DataGridViewComboBoxColumn();
            combo.DataSource = keshiList;
            combo.ValueMember = "KeshiCode";
            combo.DisplayMember = "KeshiName";
            combo.DataPropertyName = "DoctorDeptCode";
            combo.Name = "医师科室";
            combo.ReadOnly = !isZhuyuan;
            dataGridView1.Columns.Add(combo);

            combo = new DataGridViewComboBoxColumn();
            combo.DataSource = keshiList;
            combo.ValueMember = "KeshiCode";
            combo.DisplayMember = "KeshiName";
            combo.DataPropertyName = "PatientDeptCode";
            combo.Name = "患者科室";
            combo.ReadOnly = !isZhuyuan;
            dataGridView1.Columns.Add(combo);

            DataGridViewCheckBoxColumn ckb = new DataGridViewCheckBoxColumn();
            ckb.DataPropertyName = "Cancer";
            ckb.Name = "是否癌症";
            ckb.ReadOnly = !isZhuyuan;
            dataGridView1.Columns.Add(ckb);
            // Initialize and add a check box column.
            /*
            column = new DataGridViewCheckBoxColumn();
            column.DataPropertyName = "GoodGuy";
            column.Name = "Good";
            dataGridView1.Columns.Add(column);
             */
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                dataGridView1.Rows[i].ReadOnly = true;
            }
        }

        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.ReadOnly)
                return;

            if (dataGridView1.Columns[e.ColumnIndex].ReadOnly)
            {
                SendKeys.Send("{Tab}");
                return;
            }

            if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].EditType == typeof(DataGridViewComboBoxEditingControl))
            {
                dataGridView1.BeginEdit(true);
                (dataGridView1.EditingControl as ComboBox).DroppedDown = true;

            }
        }

        private void InitNewRow(int rowIndex)
        {
            DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count - 1];
            

            if (rowIndex > 0)
            {
                for (int i = 0; i < dataGridView1.Columns.Count; i++)
                {
                    DataGridViewRow rowBefore = dataGridView1.Rows[dataGridView1.Rows.Count - 2];
                    row.Cells[i].Value = rowBefore.Cells[i].Value;
                }

                row.Cells[0].Value = Int32.Parse(row.Cells[0].Value.ToString()) + 1;
            }
            else
            {
                row.Cells[1].Value = endPicker.Value;
                row.Cells[0].Value = 1;
                if (yaopins.Count > 0)
                {
                    row.Cells[8].Value = yaopins[0].YaopinCode;
                    row.Cells[9].Value = yaopins[0].YaopinGuige;
                    row.Cells[10].Value = yaopins[0].YaopinDanwei;
                    row.Cells[18].Value = yaopins[0].YaopinBatch;

                }

                if (doctors.Count > 0)
                {
                    row.Cells[12].Value = doctors[0].YishiCode;
                    foreach (Keshi k in keshiList)
                    {
                        if (k.KeshiID == doctors[0].YishiKeshiID)
                        {
                            row.Cells[19].Value = k.KeshiCode;
                            row.Cells[20].Value = k.KeshiCode;
                        }
                    }
                }

                if (takers.Count > 0)
                    row.Cells[14].Value = takers[0].PersonName;

                if (senders.Count > 0)
                    row.Cells[16].Value = senders[0].PersonName;

                if (auditors.Count > 0)
                    row.Cells[17].Value = auditors[0].PersonName;
            }

            row.Cells[11].Value = 1;
        }

        private void RegisterZYForm_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F10)
            {
                bindingSource1.AddNew();
                InitNewRow(dataGridView1.Rows.Count - 1);
                dataGridView1.ReadOnly = false;
                dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
                dataGridView1.FirstDisplayedScrollingColumnIndex = 0;
                dataGridView1.ClearSelection();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Selected = true;
                dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2];
                dataGridView1.BeginEdit(true);
                normalColor = dataGridView1.CurrentRow.DefaultCellStyle.BackColor;
                dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.White;
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.F11)
            {
                if (!dataGridView1.ReadOnly)
                    return;

                dataGridView1.ReadOnly = false;
                dataGridView1.BeginEdit(true);

                normalColor = dataGridView1.CurrentRow.DefaultCellStyle.BackColor;
                dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.White;

                e.Handled = true;
            }
            else if (e.KeyCode == Keys.F12)
            {
                if (dataGridView1.ReadOnly)
                    return;
                
                dataGridView1.EndEdit();
                dataGridView1.ClearSelection();
                startPicker.Focus();
                dataGridView1.Focus();

                e.Handled = true;
            }
        }

        private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.ReadOnly == false)
            {
                SaveOrUpdateChufang(e.RowIndex);
                dataGridView1.ReadOnly = true;
                dataGridView1.CurrentRow.DefaultCellStyle.BackColor = normalColor;

                DataGridViewComboBoxColumn cboCol = this.dataGridView1.Columns[14] as DataGridViewComboBoxColumn;
                if (cboCol == null)
                    return;

                String takerName = dataGridView1[14, e.RowIndex].Value.ToString();
                String deptCode = dataGridView1[19, e.RowIndex].Value.ToString();
                foreach (Keshi k in keshiList)
                {
                    if (k.KeshiCode == deptCode)
                    {
                        foreach (Person p in cboCol.Items)
                        {
                            if (p.PersonName == takerName)
                            {
                                p.KeshiID = k.KeshiID;
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }

        private void SaveOrUpdateChufang(int index)
        {
            if (index >= chufangList.Count || index < 0)
            {
                MessageBox.Show("没有要更新的数据！");
                return;
            }

            Chufang c = chufangList[index];

            // 根据药品编码找到选择的药品
            foreach (Yaopin yaopin in yaopins)
            {
                if (yaopin.YaopinCode == c.YaopinCode)
                {
                    yaopin.YaopinBatch = c.BatchNo;

                    c.YaopinID = yaopin.YaopinID;
                    c.YaopinName = yaopin.YaopinName;
                    c.YaopinGuige = yaopin.YaopinGuige;
                    c.YaopinDanwei = yaopin.YaopinDanwei;
                    c.Lingyao.LingyaoYaopin = yaopin.Clone();

                    break;
                }
            }

            // 根据医生编码找到选择的医生
            foreach (Yishi yishi in doctors)
            {
                if (yishi.YishiCode == c.DoctorCode)
                {
                    c.DoctorID = yishi.YishiID;
                    c.Doctor = yishi.Clone();
                    break;
                }
            }

            // 根据科室编码找到医生科室
            foreach (Keshi keshi in keshiList)
            {
                if (keshi.KeshiCode == c.DoctorDeptCode)
                {
                    c.DoctorDept = keshi.Clone();
                    break;
                }
            }

            // 根据科室编码找到病人科室
            foreach (Keshi keshi in keshiList)
            {
                if (keshi.KeshiCode == c.PatientDeptCode)
                {
                    c.PatientDept = keshi.Clone();
                    break;
                }
            }

            c.Lingyao.LingyaoDate = DateTime.Parse(c.Lingyao.LingyaoDate.ToShortDateString());
            c.IsHospital = this.IsZhuyuan?1:0;
            if (c.Lingyao.LingyaoID == "")
            {
                c.Lingyao.LingyaoID = AnesthesiaBLL.AddChufang(c);
            }
            else
                AnesthesiaBLL.ModifyChufang(c);
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 8 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) // 药品
            {

                foreach (Yaopin yaopin in yaopins)
                {
                    if (yaopin.YaopinCode == dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString())
                    {
                        dataGridView1[e.ColumnIndex + 1, e.RowIndex].Value = yaopin.YaopinGuige;
                        dataGridView1[e.ColumnIndex + 2, e.RowIndex].Value = yaopin.YaopinDanwei;
                        dataGridView1[18, e.RowIndex].Value = yaopin.YaopinBatch;
                    }
                }
            }
            if (e.ColumnIndex == 12 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) // 医师
            {
                foreach (Yishi yishi in doctors)
                {
                    if (yishi.YishiCode == dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString())
                    {
                        Keshi k = null;
                        foreach (Keshi keshi in keshiList)
                        {
                            if (keshi.KeshiID == yishi.YishiKeshiID)
                            {
                                k = keshi;
                                break;
                            }
                        }

                        if (k != null)
                        {
                            dataGridView1[19, e.RowIndex].Value = k.KeshiCode;
                            dataGridView1[20, e.RowIndex].Value = k.KeshiCode;

                            DataGridViewComboBoxColumn cboCol = this.dataGridView1.Columns[14] as DataGridViewComboBoxColumn;
                            if (cboCol == null)
                                return;

                            foreach (Person p in cboCol.Items)
                            {
                                if (p.KeshiID == k.KeshiID)
                                {
                                    dataGridView1[14, e.RowIndex].Value = p.PersonName;
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)    //监听回车事件
            {
                if (this.dataGridView1.IsCurrentCellInEditMode)   //如果当前单元格处于编辑模式
                {
                    SendKeys.Send("{Up}");
                    SendKeys.Send("{Tab}");
                }
                return true;
            }
            else if (keyData == Keys.Delete)
            {
                if (dataGridView1.IsCurrentCellInEditMode || !dataGridView1.ReadOnly)
                {
                    MessageBox.Show("处于编辑状态不能删除处方！", "医院", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return true;
                }

                if (dataGridView1.SelectedRows.Count == 0)
                {
                    MessageBox.Show("请先选择处方！", "医院", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return true;
                }

                if (MessageBox.Show("处方删除后将不能回复。是否确定要删除？", "医院", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                    return true;

                foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
                {
                    AnesthesiaBLL.DeleteChufang(chufangList[dr.Index]);
                    dataGridView1.Rows.Remove(dr);
                }

            }
            else if (keyData == Keys.Escape)
            {
                try
                {
                    if (!dataGridView1.ReadOnly)
                    {
                        dataGridView1.DataError +=new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
                        dataGridView1.CancelEdit();
                        int row = dataGridView1.CurrentRow.Index;
                        if (String.IsNullOrEmpty(chufangList[row].Lingyao.LingyaoID))
                        {
                            dataGridView1.Rows.RemoveAt(row);
                        }
                        dataGridView1.DataError -= new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
                        LoadChufangList();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("读取数据失败！", "医院", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (e.ColumnIndex == 14 || e.ColumnIndex == 16 || e.ColumnIndex == 17)
            {
                String value = e.FormattedValue.ToString();
                if (String.IsNullOrEmpty(value.Trim()))
                    return;

                for (int i = 0; i < value.Length; i++)
                {
                    if ((value[i] >= 'a' && value[i] <= 'z') || (value[i] >= 'A' && value[i] <= 'Z'))
                        return;
                }

                DataGridViewComboBoxColumn cboCol = this.dataGridView1.Columns[e.ColumnIndex] as DataGridViewComboBoxColumn;
                if (cboCol == null)
                    return;


                // Add value to list if not there
                bool isExist = false;
                foreach (Person p in cboCol.Items)
                {
                    if (p.PersonName == value)
                    {
                        isExist = true;
                        break;
                    }
                }

                if (!isExist && cboCol.Items.IndexOf(value) == -1)
                {
                    // Must add to both the current combobox as well as the template, to avoid duplicate entries
                    DataGridViewComboBoxCell cell = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewComboBoxCell;
                    if (cell != null)
                    {
                        Person p = new Person();
                        p.PersonName = value;
                        p.IsZhuyuan = IsZhuyuan? 1: 0;
                        cboCol.Items.Insert(0, p);
                        cell.Items.Insert(0, p);
                    }
                }

                dataGridView1.CurrentCell.Value = value;
            }
        }

        private void toolStripComboBoxDrug_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!initCompleted)
                return;

            try
            {
                LoadChufangList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("读取数据失败！", "医院", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            e.Cancel = true;
            e.ThrowException = false;
        }

    }

    public class Sex
    {
        private int sexIndex = 0;
        private string sexLabel = "女";

        public Sex(int i, string l)
        {
            sexIndex = i;
            sexLabel = l;
        }

        public int SexIndex
        {
            get { return sexIndex; }
            set { sexIndex = value; }
        }

        public string SexLabel
        {
            get { return sexLabel; }
            set { sexLabel = value; }
        }

    }
}
